package jagex.client;

import java.awt.Component;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.ColorModel;
import java.awt.image.DirectColorModel;
import java.awt.image.ImageConsumer;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;

public class GameImage implements ImageProducer, ImageObserver {

	public GameImage(int width, int height, int arg2, Component component) {
		mk = true;
		rk = false;
		vk = false;
		ak = component;
		imageHeight = height;
		imageWidth = width;
		imageWidthUnused = menuDefaultWidth = width;
		imageHeightUnused = menuDefaultHeight = height;
		uj = width * height;
		imagePixelArray = new int[width * height];
		ck = new int[arg2][];
		lk = new boolean[arg2];
		dk = new byte[arg2][];
		ek = new int[arg2][];
		fk = new int[arg2];
		gk = new int[arg2];
		jk = new int[arg2];
		kk = new int[arg2];
		hk = new int[arg2];
		ik = new int[arg2];
		if (width > 1 && height > 1 && component != null) {
			colourModel = new DirectColorModel(32, 0xff0000, 65280, 255);
			int j = menuDefaultWidth * menuDefaultHeight;
			for (int k = 0; k < j; k++) {
				imagePixelArray[k] = 0;
			}

			image = component.createImage(this);
			completePixels();
			component.prepareImage(image, component);
			completePixels();
			component.prepareImage(image, component);
			completePixels();
			component.prepareImage(image, component);
		}
	}

	public synchronized void qg(int arg0, int arg1) {
		if (menuDefaultWidth > imageWidthUnused) {
			menuDefaultWidth = imageWidthUnused;
		}
		if (menuDefaultHeight > imageHeightUnused) {
			menuDefaultHeight = imageHeightUnused;
		}
		menuDefaultWidth = arg0;
		menuDefaultHeight = arg1;
		uj = arg0 * arg1;
	}

	public synchronized void addConsumer(ImageConsumer imageconsumer) {
		imageConsumer = imageconsumer;
		imageconsumer.setDimensions(menuDefaultWidth, menuDefaultHeight);
		imageconsumer.setProperties(null);
		imageconsumer.setColorModel(colourModel);
		imageconsumer.setHints(14);
	}

	public synchronized boolean isConsumer(ImageConsumer imageconsumer) {
		return imageConsumer == imageconsumer;
	}

	public synchronized void removeConsumer(ImageConsumer imageconsumer) {
		if (imageConsumer == imageconsumer) {
			imageConsumer = null;
		}
	}

	public void startProduction(ImageConsumer imageconsumer) {
		addConsumer(imageconsumer);
	}

	public void requestTopDownLeftRightResend(ImageConsumer arg0) {
		System.out.println("TDLR");
	}

	public synchronized void completePixels() {
		if (imageConsumer == null) {
			return;
		} else {
			imageConsumer.setPixels(0, 0, menuDefaultWidth, menuDefaultHeight,
					colourModel, imagePixelArray, 0, menuDefaultWidth);
			imageConsumer.imageComplete(2);
			return;
		}
	}

	public void setDimensions(int x, int y, int width, int height) {
		if (x < 0) {
			x = 0;
		}
		if (y < 0) {
			y = 0;
		}
		if (width > menuDefaultWidth) {
			width = menuDefaultWidth;
		}
		if (height > menuDefaultHeight) {
			height = menuDefaultHeight;
		}
		imageX = x;
		imageY = y;
		imageWidth = width;
		imageHeight = height;
	}

	public void resetDimensions() {
		imageX = 0;
		imageY = 0;
		imageWidth = menuDefaultWidth;
		imageHeight = menuDefaultHeight;
	}

	public void drawImage(Graphics g, int x, int y) {
		completePixels();
		g.drawImage(image, x, y, this);
	}

	public void df() {
		int j = menuDefaultWidth * menuDefaultHeight;
		if (!rk) {
			for (int k = 0; k < j; k++) {
				imagePixelArray[k] = 0;
			}

			return;
		}
		int l = 0;
		for (int i1 = -menuDefaultHeight; i1 < 0; i1 += 2) {
			for (int j1 = -menuDefaultWidth; j1 < 0; j1++) {
				imagePixelArray[l++] = 0;
			}

			l += menuDefaultWidth;
		}

	}

	public void rf(int arg0, int arg1, int arg2, int arg3, int arg4) {
		int j = 256 - arg4;
		int k = (arg3 >> 16 & 0xff) * arg4;
		int l = (arg3 >> 8 & 0xff) * arg4;
		int i1 = (arg3 & 0xff) * arg4;
		int i2 = arg1 - arg2;
		if (i2 < 0) {
			i2 = 0;
		}
		int j2 = arg1 + arg2;
		if (j2 >= menuDefaultHeight) {
			j2 = menuDefaultHeight - 1;
		}
		byte byte0 = 1;
		if (rk) {
			byte0 = 2;
			if ((i2 & 1) != 0) {
				i2++;
			}
		}
		for (int k2 = i2; k2 <= j2; k2 += byte0) {
			int l2 = k2 - arg1;
			int i3 = (int) Math.sqrt(arg2 * arg2 - l2 * l2);
			int j3 = arg0 - i3;
			if (j3 < 0) {
				j3 = 0;
			}
			int k3 = arg0 + i3;
			if (k3 >= menuDefaultWidth) {
				k3 = menuDefaultWidth - 1;
			}
			int l3 = j3 + k2 * menuDefaultWidth;
			for (int i4 = j3; i4 <= k3; i4++) {
				int j1 = (imagePixelArray[l3] >> 16 & 0xff) * j;
				int k1 = (imagePixelArray[l3] >> 8 & 0xff) * j;
				int l1 = (imagePixelArray[l3] & 0xff) * j;
				int j4 = ((k + j1 >> 8) << 16) + ((l + k1 >> 8) << 8)
						+ (i1 + l1 >> 8);
				imagePixelArray[l3++] = j4;
			}

		}

	}

	public void nf(int arg0, int arg1, int arg2, int arg3, int arg4, int arg5) {
		if (arg0 < imageX) {
			arg2 -= imageX - arg0;
			arg0 = imageX;
		}
		if (arg1 < imageY) {
			arg3 -= imageY - arg1;
			arg1 = imageY;
		}
		if (arg0 + arg2 > imageWidth) {
			arg2 = imageWidth - arg0;
		}
		if (arg1 + arg3 > imageHeight) {
			arg3 = imageHeight - arg1;
		}
		int j = 256 - arg5;
		int k = (arg4 >> 16 & 0xff) * arg5;
		int l = (arg4 >> 8 & 0xff) * arg5;
		int i1 = (arg4 & 0xff) * arg5;
		int i2 = menuDefaultWidth - arg2;
		byte byte0 = 1;
		if (rk) {
			byte0 = 2;
			i2 += menuDefaultWidth;
			if ((arg1 & 1) != 0) {
				arg1++;
				arg3--;
			}
		}
		int j2 = arg0 + arg1 * menuDefaultWidth;
		for (int k2 = 0; k2 < arg3; k2 += byte0) {
			for (int l2 = -arg2; l2 < 0; l2++) {
				int j1 = (imagePixelArray[j2] >> 16 & 0xff) * j;
				int k1 = (imagePixelArray[j2] >> 8 & 0xff) * j;
				int l1 = (imagePixelArray[j2] & 0xff) * j;
				int i3 = ((k + j1 >> 8) << 16) + ((l + k1 >> 8) << 8)
						+ (i1 + l1 >> 8);
				imagePixelArray[j2++] = i3;
			}

			j2 += i2;
		}

	}

	public void ag(int arg0, int arg1, int arg2, int arg3, int arg4, int arg5) {
		if (arg0 < imageX) {
			arg2 -= imageX - arg0;
			arg0 = imageX;
		}
		if (arg0 + arg2 > imageWidth) {
			arg2 = imageWidth - arg0;
		}
		int j = arg5 >> 16 & 0xff;
		int k = arg5 >> 8 & 0xff;
		int l = arg5 & 0xff;
		int i1 = arg4 >> 16 & 0xff;
		int j1 = arg4 >> 8 & 0xff;
		int k1 = arg4 & 0xff;
		int l1 = menuDefaultWidth - arg2;
		byte byte0 = 1;
		if (rk) {
			byte0 = 2;
			l1 += menuDefaultWidth;
			if ((arg1 & 1) != 0) {
				arg1++;
				arg3--;
			}
		}
		int i2 = arg0 + arg1 * menuDefaultWidth;
		for (int j2 = 0; j2 < arg3; j2 += byte0) {
			if (j2 + arg1 >= imageY && j2 + arg1 < imageHeight) {
				int k2 = ((j * j2 + i1 * (arg3 - j2)) / arg3 << 16)
						+ ((k * j2 + j1 * (arg3 - j2)) / arg3 << 8)
						+ (l * j2 + k1 * (arg3 - j2)) / arg3;
				for (int l2 = -arg2; l2 < 0; l2++) {
					imagePixelArray[i2++] = k2;
				}

				i2 += l1;
			} else {
				i2 += menuDefaultWidth;
			}
		}

	}

	public void drawBox(int arg0, int arg1, int arg2, int arg3, int arg4) {
		if (arg0 < imageX) {
			arg2 -= imageX - arg0;
			arg0 = imageX;
		}
		if (arg1 < imageY) {
			arg3 -= imageY - arg1;
			arg1 = imageY;
		}
		if (arg0 + arg2 > imageWidth) {
			arg2 = imageWidth - arg0;
		}
		if (arg1 + arg3 > imageHeight) {
			arg3 = imageHeight - arg1;
		}
		int j = menuDefaultWidth - arg2;
		byte byte0 = 1;
		if (rk) {
			byte0 = 2;
			j += menuDefaultWidth;
			if ((arg1 & 1) != 0) {
				arg1++;
				arg3--;
			}
		}
		int k = arg0 + arg1 * menuDefaultWidth;
		for (int l = -arg3; l < 0; l += byte0) {
			for (int i1 = -arg2; i1 < 0; i1++) {
				imagePixelArray[k++] = arg4;
			}

			k += j;
		}

	}

	public void drawBoxEdge(int x1, int y1, int x2, int y2, int colour) {
		drawLineX(x1, y1, x2, colour);
		drawLineX(x1, (y1 + y2) - 1, x2, colour);
		drawLineY(x1, y1, y2, colour);
		drawLineY((x1 + x2) - 1, y1, y2, colour);
	}

	public void drawLineX(int x1, int y1, int x2, int colour) {
		if (y1 < imageY || y1 >= imageHeight) {
			return;
		}
		if (x1 < imageX) {
			x2 -= imageX - x1;
			x1 = imageX;
		}
		if (x1 + x2 > imageWidth) {
			x2 = imageWidth - x1;
		}
		int xPixel = x1 + y1 * menuDefaultWidth;
		for (int yPixel = 0; yPixel < x2; yPixel++) {
			imagePixelArray[xPixel + yPixel] = colour;
		}

	}

	public void drawLineY(int x1, int y1, int y2, int colour) {
		if (x1 < imageX || x1 >= imageWidth) {
			return;
		}
		if (y1 < imageY) {
			y2 -= imageY - y1;
			y1 = imageY;
		}
		if (y1 + y2 > imageWidth) {
			y2 = imageHeight - y1;
		}
		int xPixel = x1 + y1 * menuDefaultWidth;
		for (int yPixel = 0; yPixel < y2; yPixel++) {
			imagePixelArray[xPixel + yPixel * menuDefaultWidth] = colour;
		}

	}

	public void setPixelColour(int x, int y, int colour) {
		if (x < imageX || y < imageY || x >= imageWidth || y >= imageHeight) {
			return;
		} else {
			imagePixelArray[x + y * menuDefaultWidth] = colour;
			return;
		}
	}

	public void fadePixels() {
		int l = menuDefaultWidth * menuDefaultHeight;
		for (int k = 0; k < l; k++) {
			int j = imagePixelArray[k] & 0xffffff;
			imagePixelArray[k] = (j >>> 1 & 0x7f7f7f) + (j >>> 2 & 0x3f3f3f)
					+ (j >>> 3 & 0x1f1f1f) + (j >>> 4 & 0xf0f0f);
		}

	}

	public static int convertRGBtoLong(int red, int green, int blue) {
		return (red << 16) + (green << 8) + blue;
	}

	public void cleanupSprites() {
		for (int j = 0; j < ck.length; j++) {
			ck[j] = null;
			fk[j] = 0;
			gk[j] = 0;
			dk[j] = null;
			ek[j] = null;
		}

	}

	public void eg(byte arg0[], int arg1, int arg2, boolean arg3, boolean arg4) {
		cg(arg0, arg1, arg2, arg3, 1, 1, arg4);
	}

	public void jg(byte arg0[], int arg1, int arg2, boolean arg3, int arg4,
			boolean arg5) {
		cg(arg0, arg1, arg2, arg3, arg4, 1, arg5);
	}

	public void cg(byte arg0[], int arg1, int arg2, boolean arg3, int arg4,
			int arg5, boolean arg6) {
		int j = (arg0[13 + arg1] & 0xff) * 256 + (arg0[12 + arg1] & 0xff);
		int k = (arg0[15 + arg1] & 0xff) * 256 + (arg0[14 + arg1] & 0xff);
		int l = -1;
		int ai[] = new int[256];
		for (int i1 = 0; i1 < 256; i1++) {
			ai[i1] = 0xff000000 + ((arg0[arg1 + 20 + i1 * 3] & 0xff) << 16)
					+ ((arg0[arg1 + 19 + i1 * 3] & 0xff) << 8)
					+ (arg0[arg1 + 18 + i1 * 3] & 0xff);
			if (ai[i1] == -65281) {
				l = i1;
			}
		}

		if (l == -1) {
			arg3 = false;
		}
		if (arg6 && arg3) {
			ai[l] = ai[0];
		}
		int j1 = j / arg4;
		int k1 = k / arg5;
		int ai1[] = new int[j1 * k1];
		for (int l1 = 0; l1 < arg5; l1++) {
			for (int i2 = 0; i2 < arg4; i2++) {
				int j2 = 0;
				for (int k2 = k1 * l1; k2 < k1 * (l1 + 1); k2++) {
					for (int l2 = j1 * i2; l2 < j1 * (i2 + 1); l2++) {
						if (arg6) {
							ai1[j2++] = arg0[arg1 + 786 + l2 + (k - k2 - 1) * j] & 0xff;
						} else {
							ai1[j2++] = ai[arg0[arg1 + 786 + l2 + (k - k2 - 1)
									* j] & 0xff];
						}
					}

				}

				if (arg6) {
					af(ai1, j1, k1, arg2++, arg3, ai, l);
				} else {
					af(ai1, j1, k1, arg2++, arg3, null, -65281);
				}
			}

		}

	}

	private void af(int arg0[], int arg1, int arg2, int arg3, boolean arg4,
			int arg5[], int arg6) {
		int j = 0;
		int k = 0;
		int l = arg1;
		int i1 = arg2;
		if (arg4 && mk) {
			label0: for (int j1 = 0; j1 < arg2; j1++) {
				for (int i2 = 0; i2 < arg1; i2++) {
					int i3 = arg0[i2 + j1 * arg1];
					if (i3 == arg6) {
						continue;
					}
					k = j1;
					break label0;
				}

			}

			label1: for (int j2 = 0; j2 < arg1; j2++) {
				for (int j3 = 0; j3 < arg2; j3++) {
					int j4 = arg0[j2 + j3 * arg1];
					if (j4 == arg6) {
						continue;
					}
					j = j2;
					break label1;
				}

			}

			label2: for (int k3 = arg2 - 1; k3 >= 0; k3--) {
				for (int k4 = 0; k4 < arg1; k4++) {
					int k5 = arg0[k4 + k3 * arg1];
					if (k5 == arg6) {
						continue;
					}
					i1 = k3 + 1;
					break label2;
				}

			}

			label3: for (int l4 = arg1 - 1; l4 >= 0; l4--) {
				for (int l5 = 0; l5 < arg2; l5++) {
					int i6 = arg0[l4 + l5 * arg1];
					if (i6 == arg6) {
						continue;
					}
					l = l4 + 1;
					break label3;
				}

			}

		}
		fk[arg3] = l - j;
		gk[arg3] = i1 - k;
		lk[arg3] = arg4;
		hk[arg3] = j;
		ik[arg3] = k;
		jk[arg3] = arg1;
		kk[arg3] = arg2;
		if (arg5 == null) {
			ck[arg3] = new int[(l - j) * (i1 - k)];
			int k1 = 0;
			for (int k2 = k; k2 < i1; k2++) {
				for (int l3 = j; l3 < l; l3++) {
					int i5 = arg0[l3 + k2 * arg1];
					if (arg4) {
						if (i5 == arg6) {
							i5 = 0;
						}
						if (i5 == 0xff000000) {
							i5 = 0xff010101;
						}
					}
					ck[arg3][k1++] = i5 & 0xffffff;
				}

			}

			return;
		}
		dk[arg3] = new byte[(l - j) * (i1 - k)];
		ek[arg3] = arg5;
		int l1 = 0;
		for (int l2 = k; l2 < i1; l2++) {
			for (int i4 = j; i4 < l; i4++) {
				int j5 = arg0[i4 + l2 * arg1];
				if (arg4) {
					if (j5 == arg6) {
						j5 = 0;
					} else if (j5 == 0) {
						j5 = arg6;
					}
				}
				dk[arg3][l1++] = (byte) j5;
			}

		}

	}

	public void jf(int arg0, int arg1, int arg2, int arg3, int arg4) {
		fk[arg0] = arg3;
		gk[arg0] = arg4;
		lk[arg0] = false;
		hk[arg0] = 0;
		ik[arg0] = 0;
		jk[arg0] = arg3;
		kk[arg0] = arg4;
		int j = arg3 * arg4;
		int k = 0;
		ck[arg0] = new int[j];
		for (int l = arg1; l < arg1 + arg3; l++) {
			for (int i1 = arg2; i1 < arg2 + arg4; i1++) {
				ck[arg0][k++] = imagePixelArray[l + i1 * menuDefaultWidth];
			}

		}

	}

	public void _mthif(int arg0, int arg1, int arg2) {
		drawPicutre(arg0 - jk[arg2] / 2, arg1 - kk[arg2] / 2, arg2);
	}

	public void drawPicutre(int arg0, int arg1, int arg2) {
		if (lk[arg2]) {
			arg0 += hk[arg2];
			arg1 += ik[arg2];
		}
		int j = arg0 + arg1 * menuDefaultWidth;
		int k = 0;
		int l = gk[arg2];
		int i1 = fk[arg2];
		int j1 = menuDefaultWidth - i1;
		int k1 = 0;
		if (arg1 < imageY) {
			int l1 = imageY - arg1;
			l -= l1;
			arg1 = imageY;
			k += l1 * i1;
			j += l1 * menuDefaultWidth;
		}
		if (arg1 + l >= imageHeight) {
			l -= ((arg1 + l) - imageHeight) + 1;
		}
		if (arg0 < imageX) {
			int i2 = imageX - arg0;
			i1 -= i2;
			arg0 = imageX;
			k += i2;
			j += i2;
			k1 += i2;
			j1 += i2;
		}
		if (arg0 + i1 >= imageWidth) {
			int j2 = ((arg0 + i1) - imageWidth) + 1;
			i1 -= j2;
			k1 += j2;
			j1 += j2;
		}
		if (i1 <= 0 || l <= 0) {
			return;
		}
		byte byte0 = 1;
		if (rk) {
			byte0 = 2;
			j1 += menuDefaultWidth;
			k1 += fk[arg2];
			if ((arg1 & 1) != 0) {
				j += menuDefaultWidth;
				l--;
			}
		}
		if (lk[arg2]) {
			ff(imagePixelArray, ck[arg2], 0, k, j, i1, l, j1, k1, byte0);
			return;
		} else {
			tg(imagePixelArray, ck[arg2], k, j, i1, l, j1, k1, byte0);
			return;
		}
	}

	private void tg(int arg0[], int arg1[], int arg2, int arg3, int arg4,
			int arg5, int arg6, int arg7, int arg8) {
		int j = -(arg4 >> 2);
		arg4 = -(arg4 & 3);
		for (int k = -arg5; k < 0; k += arg8) {
			for (int l = j; l < 0; l++) {
				arg0[arg3++] = arg1[arg2++];
				arg0[arg3++] = arg1[arg2++];
				arg0[arg3++] = arg1[arg2++];
				arg0[arg3++] = arg1[arg2++];
			}

			for (int i1 = arg4; i1 < 0; i1++) {
				arg0[arg3++] = arg1[arg2++];
			}

			arg3 += arg6;
			arg2 += arg7;
		}

	}

	private void ff(int arg0[], int arg1[], int arg2, int arg3, int arg4,
			int arg5, int arg6, int arg7, int arg8, int arg9) {
		int j = -(arg5 >> 2);
		arg5 = -(arg5 & 3);
		for (int k = -arg6; k < 0; k += arg9) {
			for (int l = j; l < 0; l++) {
				arg2 = arg1[arg3++];
				if (arg2 != 0) {
					arg0[arg4++] = arg2;
				} else {
					arg4++;
				}
				arg2 = arg1[arg3++];
				if (arg2 != 0) {
					arg0[arg4++] = arg2;
				} else {
					arg4++;
				}
				arg2 = arg1[arg3++];
				if (arg2 != 0) {
					arg0[arg4++] = arg2;
				} else {
					arg4++;
				}
				arg2 = arg1[arg3++];
				if (arg2 != 0) {
					arg0[arg4++] = arg2;
				} else {
					arg4++;
				}
			}

			for (int i1 = arg5; i1 < 0; i1++) {
				arg2 = arg1[arg3++];
				if (arg2 != 0) {
					arg0[arg4++] = arg2;
				} else {
					arg4++;
				}
			}

			arg4 += arg7;
			arg3 += arg8;
		}

	}

	public void vf(int arg0, int arg1, int arg2) {
		if (lk[arg2]) {
			arg0 += hk[arg2];
			arg1 += ik[arg2];
		}
		int j = arg0 + arg1 * menuDefaultWidth;
		int k = 0;
		int l = gk[arg2];
		int i1 = fk[arg2];
		int j1 = menuDefaultWidth - i1;
		int k1 = 0;
		if (arg1 < imageY) {
			int l1 = imageY - arg1;
			l -= l1;
			arg1 = imageY;
			k += l1 * i1;
			j += l1 * menuDefaultWidth;
		}
		if (arg1 + l >= imageHeight) {
			l -= ((arg1 + l) - imageHeight) + 1;
		}
		if (arg0 < imageX) {
			int i2 = imageX - arg0;
			i1 -= i2;
			arg0 = imageX;
			k += i2;
			j += i2;
			k1 += i2;
			j1 += i2;
		}
		if (arg0 + i1 >= imageWidth) {
			int j2 = ((arg0 + i1) - imageWidth) + 1;
			i1 -= j2;
			k1 += j2;
			j1 += j2;
		}
		if (i1 <= 0 || l <= 0) {
			return;
		}
		byte byte0 = 1;
		if (rk) {
			byte0 = 2;
			j1 += menuDefaultWidth;
			k1 += fk[arg2];
			if ((arg1 & 1) != 0) {
				j += menuDefaultWidth;
				l--;
			}
		}
		pg(imagePixelArray, ck[arg2], 0, k, j, i1, l, j1, k1, byte0);
	}

	private void pg(int arg0[], int arg1[], int arg2, int arg3, int arg4,
			int arg5, int arg6, int arg7, int arg8, int arg9) {
		int j = -(arg5 >> 2);
		arg5 = -(arg5 & 3);
		for (int k = -arg6; k < 0; k += arg9) {
			for (int l = j; l < 0; l++) {
				arg2 = arg1[arg3++];
				if (arg2 != 0) {
					arg0[arg4++] = (arg2 >> 1 & 0x7f7f7f)
							+ (arg0[arg4] >> 1 & 0x7f7f7f);
				} else {
					arg4++;
				}
				arg2 = arg1[arg3++];
				if (arg2 != 0) {
					arg0[arg4++] = (arg2 >> 1 & 0x7f7f7f)
							+ (arg0[arg4] >> 1 & 0x7f7f7f);
				} else {
					arg4++;
				}
				arg2 = arg1[arg3++];
				if (arg2 != 0) {
					arg0[arg4++] = (arg2 >> 1 & 0x7f7f7f)
							+ (arg0[arg4] >> 1 & 0x7f7f7f);
				} else {
					arg4++;
				}
				arg2 = arg1[arg3++];
				if (arg2 != 0) {
					arg0[arg4++] = (arg2 >> 1 & 0x7f7f7f)
							+ (arg0[arg4] >> 1 & 0x7f7f7f);
				} else {
					arg4++;
				}
			}

			for (int i1 = arg5; i1 < 0; i1++) {
				arg2 = arg1[arg3++];
				if (arg2 != 0) {
					arg0[arg4++] = (arg2 >> 1 & 0x7f7f7f)
							+ (arg0[arg4] >> 1 & 0x7f7f7f);
				} else {
					arg4++;
				}
			}

			arg4 += arg7;
			arg3 += arg8;
		}

	}

	public void gf(int arg0, int arg1, int arg2, int arg3, int arg4) {
		int j = menuDefaultWidth;
		int k = menuDefaultHeight;
		if (wk == null) {
			wk = new int[512];
			for (int l = 0; l < 256; l++) {
				wk[l] = (int) (Math.sin((double) l * 0.02454369D) * 32768D);
				wk[l + 256] = (int) (Math.cos((double) l * 0.02454369D) * 32768D);
			}

		}
		int i1 = -jk[arg2] / 2;
		int j1 = -kk[arg2] / 2;
		if (lk[arg2]) {
			i1 += hk[arg2];
			j1 += ik[arg2];
		}
		int k1 = i1 + fk[arg2];
		int l1 = j1 + gk[arg2];
		int i2 = k1;
		int j2 = j1;
		int k2 = i1;
		int l2 = l1;
		arg3 &= 0xff;
		int i3 = wk[arg3] * arg4;
		int j3 = wk[arg3 + 256] * arg4;
		int k3 = arg0 + (j1 * i3 + i1 * j3 >> 22);
		int l3 = arg1 + (j1 * j3 - i1 * i3 >> 22);
		int i4 = arg0 + (j2 * i3 + i2 * j3 >> 22);
		int j4 = arg1 + (j2 * j3 - i2 * i3 >> 22);
		int k4 = arg0 + (l1 * i3 + k1 * j3 >> 22);
		int l4 = arg1 + (l1 * j3 - k1 * i3 >> 22);
		int i5 = arg0 + (l2 * i3 + k2 * j3 >> 22);
		int j5 = arg1 + (l2 * j3 - k2 * i3 >> 22);
		int k5 = l3;
		int l5 = l3;
		if (j4 < k5) {
			k5 = j4;
		} else if (j4 > l5) {
			l5 = j4;
		}
		if (l4 < k5) {
			k5 = l4;
		} else if (l4 > l5) {
			l5 = l4;
		}
		if (j5 < k5) {
			k5 = j5;
		} else if (j5 > l5) {
			l5 = j5;
		}
		if (k5 < imageY) {
			k5 = imageY;
		}
		if (l5 > imageHeight) {
			l5 = imageHeight;
		}
		if (xk == null || xk.length != k + 1) {
			xk = new int[k + 1];
			yk = new int[k + 1];
			zk = new int[k + 1];
			al = new int[k + 1];
			bl = new int[k + 1];
			cl = new int[k + 1];
		}
		for (int i6 = k5; i6 <= l5; i6++) {
			xk[i6] = 0x5f5e0ff;
			yk[i6] = 0xfa0a1f01;
		}

		int i7 = 0;
		int k7 = 0;
		int i8 = 0;
		int j8 = fk[arg2];
		int k8 = gk[arg2];
		i1 = 0;
		j1 = 0;
		i2 = j8 - 1;
		j2 = 0;
		k1 = j8 - 1;
		l1 = k8 - 1;
		k2 = 0;
		l2 = k8 - 1;
		if (j5 != l3) {
			i7 = (i5 - k3 << 8) / (j5 - l3);
			i8 = (l2 - j1 << 8) / (j5 - l3);
		}
		int j6;
		int k6;
		int l6;
		int l7;
		if (l3 > j5) {
			l6 = i5 << 8;
			l7 = l2 << 8;
			j6 = j5;
			k6 = l3;
		} else {
			l6 = k3 << 8;
			l7 = j1 << 8;
			j6 = l3;
			k6 = j5;
		}
		if (j6 < 0) {
			l6 -= i7 * j6;
			l7 -= i8 * j6;
			j6 = 0;
		}
		if (k6 > k - 1) {
			k6 = k - 1;
		}
		for (int l8 = j6; l8 <= k6; l8++) {
			xk[l8] = yk[l8] = l6;
			l6 += i7;
			zk[l8] = al[l8] = 0;
			bl[l8] = cl[l8] = l7;
			l7 += i8;
		}

		if (j4 != l3) {
			i7 = (i4 - k3 << 8) / (j4 - l3);
			k7 = (i2 - i1 << 8) / (j4 - l3);
		}
		int j7;
		if (l3 > j4) {
			l6 = i4 << 8;
			j7 = i2 << 8;
			j6 = j4;
			k6 = l3;
		} else {
			l6 = k3 << 8;
			j7 = i1 << 8;
			j6 = l3;
			k6 = j4;
		}
		if (j6 < 0) {
			l6 -= i7 * j6;
			j7 -= k7 * j6;
			j6 = 0;
		}
		if (k6 > k - 1) {
			k6 = k - 1;
		}
		for (int i9 = j6; i9 <= k6; i9++) {
			if (l6 < xk[i9]) {
				xk[i9] = l6;
				zk[i9] = j7;
				bl[i9] = 0;
			}
			if (l6 > yk[i9]) {
				yk[i9] = l6;
				al[i9] = j7;
				cl[i9] = 0;
			}
			l6 += i7;
			j7 += k7;
		}

		if (l4 != j4) {
			i7 = (k4 - i4 << 8) / (l4 - j4);
			i8 = (l1 - j2 << 8) / (l4 - j4);
		}
		if (j4 > l4) {
			l6 = k4 << 8;
			j7 = k1 << 8;
			l7 = l1 << 8;
			j6 = l4;
			k6 = j4;
		} else {
			l6 = i4 << 8;
			j7 = i2 << 8;
			l7 = j2 << 8;
			j6 = j4;
			k6 = l4;
		}
		if (j6 < 0) {
			l6 -= i7 * j6;
			l7 -= i8 * j6;
			j6 = 0;
		}
		if (k6 > k - 1) {
			k6 = k - 1;
		}
		for (int j9 = j6; j9 <= k6; j9++) {
			if (l6 < xk[j9]) {
				xk[j9] = l6;
				zk[j9] = j7;
				bl[j9] = l7;
			}
			if (l6 > yk[j9]) {
				yk[j9] = l6;
				al[j9] = j7;
				cl[j9] = l7;
			}
			l6 += i7;
			l7 += i8;
		}

		if (j5 != l4) {
			i7 = (i5 - k4 << 8) / (j5 - l4);
			k7 = (k2 - k1 << 8) / (j5 - l4);
		}
		if (l4 > j5) {
			l6 = i5 << 8;
			j7 = k2 << 8;
			l7 = l2 << 8;
			j6 = j5;
			k6 = l4;
		} else {
			l6 = k4 << 8;
			j7 = k1 << 8;
			l7 = l1 << 8;
			j6 = l4;
			k6 = j5;
		}
		if (j6 < 0) {
			l6 -= i7 * j6;
			j7 -= k7 * j6;
			j6 = 0;
		}
		if (k6 > k - 1) {
			k6 = k - 1;
		}
		for (int k9 = j6; k9 <= k6; k9++) {
			if (l6 < xk[k9]) {
				xk[k9] = l6;
				zk[k9] = j7;
				bl[k9] = l7;
			}
			if (l6 > yk[k9]) {
				yk[k9] = l6;
				al[k9] = j7;
				cl[k9] = l7;
			}
			l6 += i7;
			j7 += k7;
		}

		int l9 = k5 * j;
		int ai[] = ck[arg2];
		for (int i10 = k5; i10 < l5; i10++) {
			int j10 = xk[i10] >> 8;
			int k10 = yk[i10] >> 8;
			if (k10 - j10 <= 0) {
				l9 += j;
			} else {
				int l10 = zk[i10] << 9;
				int i11 = ((al[i10] << 9) - l10) / (k10 - j10);
				int j11 = bl[i10] << 9;
				int k11 = ((cl[i10] << 9) - j11) / (k10 - j10);
				if (j10 < imageX) {
					l10 += (imageX - j10) * i11;
					j11 += (imageX - j10) * k11;
					j10 = imageX;
				}
				if (k10 > imageWidth) {
					k10 = imageWidth;
				}
				if (!rk || (i10 & 1) == 0) {
					if (!lk[arg2]) {
						sf(imagePixelArray, ai, 0, l9 + j10, l10, j11, i11,
								k11, j10 - k10, j8);
					} else {
						zf(imagePixelArray, ai, 0, l9 + j10, l10, j11, i11,
								k11, j10 - k10, j8);
					}
				}
				l9 += j;
			}
		}

	}

	private void sf(int arg0[], int arg1[], int arg2, int arg3, int arg4,
			int arg5, int arg6, int arg7, int arg8, int arg9) {
		for (arg2 = arg8; arg2 < 0; arg2++) {
			imagePixelArray[arg3++] = arg1[(arg4 >> 17) + (arg5 >> 17) * arg9];
			arg4 += arg6;
			arg5 += arg7;
		}

	}

	private void zf(int arg0[], int arg1[], int arg2, int arg3, int arg4,
			int arg5, int arg6, int arg7, int arg8, int arg9) {
		for (int j = arg8; j < 0; j++) {
			arg2 = arg1[(arg4 >> 17) + (arg5 >> 17) * arg9];
			if (arg2 != 0) {
				imagePixelArray[arg3++] = arg2;
			} else {
				arg3++;
			}
			arg4 += arg6;
			arg5 += arg7;
		}

	}

	public void xf(int arg0, int arg1, int arg2, int arg3, int arg4, int arg5) {
		try {
			int j = fk[arg4];
			int k = gk[arg4];
			int l = 0;
			int i1 = 0;
			int j1 = (j << 16) / arg2;
			int k1 = (k << 16) / arg3;
			if (lk[arg4]) {
				int l1 = jk[arg4];
				int j2 = kk[arg4];
				j1 = (l1 << 16) / arg2;
				k1 = (j2 << 16) / arg3;
				arg0 += ((hk[arg4] * arg2 + l1) - 1) / l1;
				arg1 += ((ik[arg4] * arg3 + j2) - 1) / j2;
				if ((hk[arg4] * arg2) % l1 != 0) {
					l = (l1 - (hk[arg4] * arg2) % l1 << 16) / arg2;
				}
				if ((ik[arg4] * arg3) % j2 != 0) {
					i1 = (j2 - (ik[arg4] * arg3) % j2 << 16) / arg3;
				}
				arg2 = (arg2 * (fk[arg4] - (l >> 16))) / l1;
				arg3 = (arg3 * (gk[arg4] - (i1 >> 16))) / j2;
			}
			int i2 = arg0 + arg1 * menuDefaultWidth;
			int k2 = menuDefaultWidth - arg2;
			if (arg1 < imageY) {
				int l2 = imageY - arg1;
				arg3 -= l2;
				arg1 = 0;
				i2 += l2 * menuDefaultWidth;
				i1 += k1 * l2;
			}
			if (arg1 + arg3 >= imageHeight) {
				arg3 -= ((arg1 + arg3) - imageHeight) + 1;
			}
			if (arg0 < imageX) {
				int i3 = imageX - arg0;
				arg2 -= i3;
				arg0 = 0;
				i2 += i3;
				l += j1 * i3;
				k2 += i3;
			}
			if (arg0 + arg2 >= imageWidth) {
				int j3 = ((arg0 + arg2) - imageWidth) + 1;
				arg2 -= j3;
				k2 += j3;
			}
			byte byte0 = 1;
			if (rk) {
				byte0 = 2;
				k2 += menuDefaultWidth;
				k1 += k1;
				if ((arg1 & 1) != 0) {
					i2 += menuDefaultWidth;
					arg3--;
				}
			}
			tf(imagePixelArray, ck[arg4], 0, l, i1, i2, k2, arg2, arg3, j1, k1,
					j, byte0, arg5);
			return;
		} catch (Exception _ex) {
			System.out.println("error in sprite clipping routine");
		}
	}

	private void tf(int arg0[], int arg1[], int arg2, int arg3, int arg4,
			int arg5, int arg6, int arg7, int arg8, int arg9, int arg10,
			int arg11, int arg12, int arg13) {
		int i1 = arg13 >> 16 & 0xff;
		int j1 = arg13 >> 8 & 0xff;
		int k1 = arg13 & 0xff;
		try {
			int l1 = arg3;
			for (int i2 = -arg8; i2 < 0; i2 += arg12) {
				int j2 = (arg4 >> 16) * arg11;
				for (int k2 = -arg7; k2 < 0; k2++) {
					arg2 = arg1[(arg3 >> 16) + j2];
					if (arg2 != 0) {
						int j = arg2 >> 16 & 0xff;
						int k = arg2 >> 8 & 0xff;
						int l = arg2 & 0xff;
						if (j == k && k == l) {
							arg0[arg5++] = ((j * i1 >> 8) << 16)
									+ ((k * j1 >> 8) << 8) + (l * k1 >> 8);
						} else {
							arg0[arg5++] = arg2;
						}
					} else {
						arg5++;
					}
					arg3 += arg9;
				}

				arg4 += arg10;
				arg3 = l1;
				arg5 += arg6;
			}

			return;
		} catch (Exception _ex) {
			System.out.println("error in transparent sprite plot routine");
		}
	}

	public void spriteClip(int arg0, int arg1, int arg2, int arg3, int arg4) {
		try {
			int j = fk[arg4];
			int k = gk[arg4];
			int l = 0;
			int i1 = 0;
			int j1 = (j << 16) / arg2;
			int k1 = (k << 16) / arg3;
			if (lk[arg4]) {
				int l1 = jk[arg4];
				int j2 = kk[arg4];
				j1 = (l1 << 16) / arg2;
				k1 = (j2 << 16) / arg3;
				arg0 += ((hk[arg4] * arg2 + l1) - 1) / l1;
				arg1 += ((ik[arg4] * arg3 + j2) - 1) / j2;
				if ((hk[arg4] * arg2) % l1 != 0) {
					l = (l1 - (hk[arg4] * arg2) % l1 << 16) / arg2;
				}
				if ((ik[arg4] * arg3) % j2 != 0) {
					i1 = (j2 - (ik[arg4] * arg3) % j2 << 16) / arg3;
				}
				arg2 = (arg2 * (fk[arg4] - (l >> 16))) / l1;
				arg3 = (arg3 * (gk[arg4] - (i1 >> 16))) / j2;
			}
			int i2 = arg0 + arg1 * menuDefaultWidth;
			int k2 = menuDefaultWidth - arg2;
			if (arg1 < imageY) {
				int l2 = imageY - arg1;
				arg3 -= l2;
				arg1 = 0;
				i2 += l2 * menuDefaultWidth;
				i1 += k1 * l2;
			}
			if (arg1 + arg3 >= imageHeight) {
				arg3 -= ((arg1 + arg3) - imageHeight) + 1;
			}
			if (arg0 < imageX) {
				int i3 = imageX - arg0;
				arg2 -= i3;
				arg0 = 0;
				i2 += i3;
				l += j1 * i3;
				k2 += i3;
			}
			if (arg0 + arg2 >= imageWidth) {
				int j3 = ((arg0 + arg2) - imageWidth) + 1;
				arg2 -= j3;
				k2 += j3;
			}
			byte byte0 = 1;
			if (rk) {
				byte0 = 2;
				k2 += menuDefaultWidth;
				k1 += k1;
				if ((arg1 & 1) != 0) {
					i2 += menuDefaultWidth;
					arg3--;
				}
			}
			if (lk[arg4]) {
				bg(imagePixelArray, ck[arg4], 0, l, i1, i2, k2, arg2, arg3, j1,
						k1, j, byte0);
				return;
			} else {
				hg(imagePixelArray, ck[arg4], i2, l, i1, k2, arg2, arg3, j1,
						k1, j, byte0);
				return;
			}
		} catch (Exception _ex) {
			System.out.println("error in sprite clipping routine");
		}
	}

	private void hg(int arg0[], int arg1[], int arg2, int arg3, int arg4,
			int arg5, int arg6, int arg7, int arg8, int arg9, int arg10,
			int arg11) {
		try {
			int j = arg3;
			for (int k = -arg7; k < 0; k += arg11) {
				int l = (arg4 >> 16) * arg10;
				for (int i1 = -arg6; i1 < 0; i1++) {
					arg0[arg2++] = arg1[(arg3 >> 16) + l];
					arg3 += arg8;
				}

				arg4 += arg9;
				arg3 = j;
				arg2 += arg5;
			}

			return;
		} catch (Exception _ex) {
			System.out.println("error in sprite plot routine");
		}
	}

	private void bg(int arg0[], int arg1[], int arg2, int arg3, int arg4,
			int arg5, int arg6, int arg7, int arg8, int arg9, int arg10,
			int arg11, int arg12) {
		try {
			int j = arg3;
			for (int k = -arg8; k < 0; k += arg12) {
				int l = (arg4 >> 16) * arg11;
				for (int i1 = -arg7; i1 < 0; i1++) {
					arg2 = arg1[(arg3 >> 16) + l];
					if (arg2 != 0) {
						arg0[arg5++] = arg2;
					} else {
						arg5++;
					}
					arg3 += arg9;
				}

				arg4 += arg10;
				arg3 = j;
				arg5 += arg6;
			}

			return;
		} catch (Exception _ex) {
			System.out.println("error in transparent sprite plot routine");
		}
	}

	public void wg(int arg0, int arg1, int arg2, int arg3, int arg4, int arg5) {
		int j = fk[arg4];
		int k = gk[arg4];
		int l = 0;
		int i1 = 0;
		int j1 = (j << 16) / arg2;
		int k1 = (k << 16) / arg3;
		if (lk[arg4]) {
			int l1 = jk[arg4];
			int j2 = kk[arg4];
			j1 = (l1 << 16) / arg2;
			k1 = (j2 << 16) / arg3;
			arg0 += ((hk[arg4] * arg2 + l1) - 1) / l1;
			arg1 += ((ik[arg4] * arg3 + j2) - 1) / j2;
			if ((hk[arg4] * arg2) % l1 != 0) {
				l = (l1 - (hk[arg4] * arg2) % l1 << 16) / arg2;
			}
			if ((ik[arg4] * arg3) % j2 != 0) {
				i1 = (j2 - (ik[arg4] * arg3) % j2 << 16) / arg3;
			}
			arg2 = (arg2 * (fk[arg4] - (l >> 16))) / l1;
			arg3 = (arg3 * (gk[arg4] - (i1 >> 16))) / j2;
		}
		int i2 = arg0 + arg1 * menuDefaultWidth;
		int k2 = menuDefaultWidth - arg2;
		if (arg1 < imageY) {
			int l2 = imageY - arg1;
			arg3 -= l2;
			arg1 = 0;
			i2 += l2 * menuDefaultWidth;
			i1 += k1 * l2;
		}
		if (arg1 + arg3 >= imageHeight) {
			arg3 -= ((arg1 + arg3) - imageHeight) + 1;
		}
		if (arg0 < imageX) {
			int i3 = imageX - arg0;
			arg2 -= i3;
			arg0 = 0;
			i2 += i3;
			l += j1 * i3;
			k2 += i3;
		}
		if (arg0 + arg2 >= imageWidth) {
			int j3 = ((arg0 + arg2) - imageWidth) + 1;
			arg2 -= j3;
			k2 += j3;
		}
		if (arg5 == 128) {
			ng(imagePixelArray, ck[arg4], 0, l, i1, i2, k2, arg2, arg3, j1, k1,
					j);
			return;
		} else {
			wf(imagePixelArray, ck[arg4], 0, l, i1, i2, k2, arg2, arg3, j1, k1,
					j, arg5);
			return;
		}
	}

	private void ng(int arg0[], int arg1[], int arg2, int arg3, int arg4,
			int arg5, int arg6, int arg7, int arg8, int arg9, int arg10,
			int arg11) {
		int j = arg3;
		for (int k = -arg8; k < 0; k++) {
			int l = (arg4 >> 16) * arg11;
			for (int i1 = -arg7; i1 < 0; i1++) {
				arg2 = arg1[(arg3 >> 16) + l];
				if (arg2 != 0) {
					arg0[arg5++] = (arg2 >>> 1 & 0x7f7f7f)
							+ (arg0[arg5] >>> 1 & 0x7f7f7f);
				} else {
					arg5++;
				}
				arg3 += arg9;
			}

			arg4 += arg10;
			arg3 = j;
			arg5 += arg6;
		}

	}

	private void wf(int arg0[], int arg1[], int arg2, int arg3, int arg4,
			int arg5, int arg6, int arg7, int arg8, int arg9, int arg10,
			int arg11, int arg12) {
		int j = arg3;
		int k = 256 - arg12;
		for (int j2 = -arg8; j2 < 0; j2++) {
			int k2 = (arg4 >> 16) * arg11;
			for (int l2 = -arg7; l2 < 0; l2++) {
				arg2 = arg1[(arg3 >> 16) + k2];
				if (arg2 != 0) {
					int l = (arg2 >> 16 & 0xff) * arg12;
					int i1 = (arg2 >> 8 & 0xff) * arg12;
					int j1 = (arg2 & 0xff) * arg12;
					int k1 = (arg0[arg5] >> 16 & 0xff) * k;
					int l1 = (arg0[arg5] >> 8 & 0xff) * k;
					int i2 = (arg0[arg5] & 0xff) * k;
					int i3 = ((l + k1 >> 8) << 16) + ((i1 + l1 >> 8) << 8)
							+ (j1 + i2 >> 8);
					arg0[arg5++] = i3;
				} else {
					arg5++;
				}
				arg3 += arg9;
			}

			arg4 += arg10;
			arg3 = j;
			arg5 += arg6;
		}

	}

	public void yf(int arg0, int arg1, int arg2, int arg3, int arg4, int arg5,
			int arg6) {
		spriteClip(arg0, arg1, arg2, arg3, arg4);
	}

	public void spriteClip4(int arg0, int arg1, int arg2, int arg3, int arg4,
			int arg5, int arg6, int arg7, boolean arg8) {
		try {
			if (arg5 == 0) {
				arg5 = 0xffffff;
			}
			if (arg6 == 0) {
				arg6 = 0xffffff;
			}
			int j = fk[arg4];
			int k = gk[arg4];
			int l = 0;
			int i1 = 0;
			int j1 = arg7 << 16;
			int k1 = (j << 16) / arg2;
			int l1 = (k << 16) / arg3;
			int i2 = -(arg7 << 16) / arg3;
			if (lk[arg4]) {
				int j2 = jk[arg4];
				int l2 = kk[arg4];
				k1 = (j2 << 16) / arg2;
				l1 = (l2 << 16) / arg3;
				int k3 = hk[arg4];
				int l3 = ik[arg4];
				if (arg8) {
					k3 = j2 - fk[arg4] - k3;
				}
				arg0 += ((k3 * arg2 + j2) - 1) / j2;
				int i4 = ((l3 * arg3 + l2) - 1) / l2;
				arg1 += i4;
				j1 += i4 * i2;
				if ((k3 * arg2) % j2 != 0) {
					l = (j2 - (k3 * arg2) % j2 << 16) / arg2;
				}
				if ((l3 * arg3) % l2 != 0) {
					i1 = (l2 - (l3 * arg3) % l2 << 16) / arg3;
				}
				arg2 = ((((fk[arg4] << 16) - l) + k1) - 1) / k1;
				arg3 = ((((gk[arg4] << 16) - i1) + l1) - 1) / l1;
			}
			int k2 = arg1 * menuDefaultWidth;
			j1 += arg0 << 16;
			if (arg1 < imageY) {
				int i3 = imageY - arg1;
				arg3 -= i3;
				arg1 = imageY;
				k2 += i3 * menuDefaultWidth;
				i1 += l1 * i3;
				j1 += i2 * i3;
			}
			if (arg1 + arg3 >= imageHeight) {
				arg3 -= ((arg1 + arg3) - imageHeight) + 1;
			}
			int j3 = k2 / menuDefaultWidth & 1;
			if (!rk) {
				j3 = 2;
			}
			if (arg6 == 0xffffff) {
				if (ck[arg4] != null) {
					if (!arg8) {
						xg(imagePixelArray, ck[arg4], 0, l, i1, k2, arg2, arg3,
								k1, l1, j, arg5, j1, i2, j3);
						return;
					} else {
						xg(imagePixelArray, ck[arg4], 0, (fk[arg4] << 16) - l
								- 1, i1, k2, arg2, arg3, -k1, l1, j, arg5, j1,
								i2, j3);
						return;
					}
				}
				if (!arg8) {
					bf(imagePixelArray, dk[arg4], ek[arg4], 0, l, i1, k2, arg2,
							arg3, k1, l1, j, arg5, j1, i2, j3);
					return;
				} else {
					bf(imagePixelArray, dk[arg4], ek[arg4], 0, (fk[arg4] << 16)
							- l - 1, i1, k2, arg2, arg3, -k1, l1, j, arg5, j1,
							i2, j3);
					return;
				}
			}
			if (ck[arg4] != null) {
				if (!arg8) {
					uf(imagePixelArray, ck[arg4], 0, l, i1, k2, arg2, arg3, k1,
							l1, j, arg5, arg6, j1, i2, j3);
					return;
				} else {
					uf(imagePixelArray, ck[arg4], 0, (fk[arg4] << 16) - l - 1,
							i1, k2, arg2, arg3, -k1, l1, j, arg5, arg6, j1, i2,
							j3);
					return;
				}
			}
			if (!arg8) {
				vg(imagePixelArray, dk[arg4], ek[arg4], 0, l, i1, k2, arg2,
						arg3, k1, l1, j, arg5, arg6, j1, i2, j3);
				return;
			} else {
				vg(imagePixelArray, dk[arg4], ek[arg4], 0, (fk[arg4] << 16) - l
						- 1, i1, k2, arg2, arg3, -k1, l1, j, arg5, arg6, j1,
						i2, j3);
				return;
			}
		} catch (Exception _ex) {
			System.out.println("error in sprite clipping routine");
		}
	}

	private void xg(int arg0[], int arg1[], int arg2, int arg3, int arg4,
			int arg5, int arg6, int arg7, int arg8, int arg9, int arg10,
			int arg11, int arg12, int arg13, int arg14) {
		int i1 = arg11 >> 16 & 0xff;
		int j1 = arg11 >> 8 & 0xff;
		int k1 = arg11 & 0xff;
		try {
			int l1 = arg3;
			for (int i2 = -arg7; i2 < 0; i2++) {
				int j2 = (arg4 >> 16) * arg10;
				int k2 = arg12 >> 16;
				int l2 = arg6;
				if (k2 < imageX) {
					int i3 = imageX - k2;
					l2 -= i3;
					k2 = imageX;
					arg3 += arg8 * i3;
				}
				if (k2 + l2 >= imageWidth) {
					int j3 = (k2 + l2) - imageWidth;
					l2 -= j3;
				}
				arg14 = 1 - arg14;
				if (arg14 != 0) {
					for (int k3 = k2; k3 < k2 + l2; k3++) {
						arg2 = arg1[(arg3 >> 16) + j2];
						if (arg2 != 0) {
							int j = arg2 >> 16 & 0xff;
							int k = arg2 >> 8 & 0xff;
							int l = arg2 & 0xff;
							if (j == k && k == l) {
								arg0[k3 + arg5] = ((j * i1 >> 8) << 16)
										+ ((k * j1 >> 8) << 8) + (l * k1 >> 8);
							} else {
								arg0[k3 + arg5] = arg2;
							}
						}
						arg3 += arg8;
					}

				}
				arg4 += arg9;
				arg3 = l1;
				arg5 += menuDefaultWidth;
				arg12 += arg13;
			}

			return;
		} catch (Exception _ex) {
			System.out.println("error in transparent sprite plot routine");
		}
	}

	private void uf(int arg0[], int arg1[], int arg2, int arg3, int arg4,
			int arg5, int arg6, int arg7, int arg8, int arg9, int arg10,
			int arg11, int arg12, int arg13, int arg14, int arg15) {
		int i1 = arg11 >> 16 & 0xff;
		int j1 = arg11 >> 8 & 0xff;
		int k1 = arg11 & 0xff;
		int l1 = arg12 >> 16 & 0xff;
		int i2 = arg12 >> 8 & 0xff;
		int j2 = arg12 & 0xff;
		try {
			int k2 = arg3;
			for (int l2 = -arg7; l2 < 0; l2++) {
				int i3 = (arg4 >> 16) * arg10;
				int j3 = arg13 >> 16;
				int k3 = arg6;
				if (j3 < imageX) {
					int l3 = imageX - j3;
					k3 -= l3;
					j3 = imageX;
					arg3 += arg8 * l3;
				}
				if (j3 + k3 >= imageWidth) {
					int i4 = (j3 + k3) - imageWidth;
					k3 -= i4;
				}
				arg15 = 1 - arg15;
				if (arg15 != 0) {
					for (int j4 = j3; j4 < j3 + k3; j4++) {
						arg2 = arg1[(arg3 >> 16) + i3];
						if (arg2 != 0) {
							int j = arg2 >> 16 & 0xff;
							int k = arg2 >> 8 & 0xff;
							int l = arg2 & 0xff;
							if (j == k && k == l) {
								arg0[j4 + arg5] = ((j * i1 >> 8) << 16)
										+ ((k * j1 >> 8) << 8) + (l * k1 >> 8);
							} else if (j == 255 && k == l) {
								arg0[j4 + arg5] = ((j * l1 >> 8) << 16)
										+ ((k * i2 >> 8) << 8) + (l * j2 >> 8);
							} else {
								arg0[j4 + arg5] = arg2;
							}
						}
						arg3 += arg8;
					}

				}
				arg4 += arg9;
				arg3 = k2;
				arg5 += menuDefaultWidth;
				arg13 += arg14;
			}

			return;
		} catch (Exception _ex) {
			System.out.println("error in transparent sprite plot routine");
		}
	}

	private void bf(int arg0[], byte arg1[], int arg2[], int arg3, int arg4,
			int arg5, int arg6, int arg7, int arg8, int arg9, int arg10,
			int arg11, int arg12, int arg13, int arg14, int arg15) {
		int i1 = arg12 >> 16 & 0xff;
		int j1 = arg12 >> 8 & 0xff;
		int k1 = arg12 & 0xff;
		try {
			int l1 = arg4;
			for (int i2 = -arg8; i2 < 0; i2++) {
				int j2 = (arg5 >> 16) * arg11;
				int k2 = arg13 >> 16;
				int l2 = arg7;
				if (k2 < imageX) {
					int i3 = imageX - k2;
					l2 -= i3;
					k2 = imageX;
					arg4 += arg9 * i3;
				}
				if (k2 + l2 >= imageWidth) {
					int j3 = (k2 + l2) - imageWidth;
					l2 -= j3;
				}
				arg15 = 1 - arg15;
				if (arg15 != 0) {
					for (int k3 = k2; k3 < k2 + l2; k3++) {
						arg3 = arg1[(arg4 >> 16) + j2] & 0xff;
						if (arg3 != 0) {
							arg3 = arg2[arg3];
							int j = arg3 >> 16 & 0xff;
							int k = arg3 >> 8 & 0xff;
							int l = arg3 & 0xff;
							if (j == k && k == l) {
								arg0[k3 + arg6] = ((j * i1 >> 8) << 16)
										+ ((k * j1 >> 8) << 8) + (l * k1 >> 8);
							} else {
								arg0[k3 + arg6] = arg3;
							}
						}
						arg4 += arg9;
					}

				}
				arg5 += arg10;
				arg4 = l1;
				arg6 += menuDefaultWidth;
				arg13 += arg14;
			}

			return;
		} catch (Exception _ex) {
			System.out.println("error in transparent sprite plot routine");
		}
	}

	private void vg(int arg0[], byte arg1[], int arg2[], int arg3, int arg4,
			int arg5, int arg6, int arg7, int arg8, int arg9, int arg10,
			int arg11, int arg12, int arg13, int arg14, int arg15, int arg16) {
		int i1 = arg12 >> 16 & 0xff;
		int j1 = arg12 >> 8 & 0xff;
		int k1 = arg12 & 0xff;
		int l1 = arg13 >> 16 & 0xff;
		int i2 = arg13 >> 8 & 0xff;
		int j2 = arg13 & 0xff;
		try {
			int k2 = arg4;
			for (int l2 = -arg8; l2 < 0; l2++) {
				int i3 = (arg5 >> 16) * arg11;
				int j3 = arg14 >> 16;
				int k3 = arg7;
				if (j3 < imageX) {
					int l3 = imageX - j3;
					k3 -= l3;
					j3 = imageX;
					arg4 += arg9 * l3;
				}
				if (j3 + k3 >= imageWidth) {
					int i4 = (j3 + k3) - imageWidth;
					k3 -= i4;
				}
				arg16 = 1 - arg16;
				if (arg16 != 0) {
					for (int j4 = j3; j4 < j3 + k3; j4++) {
						arg3 = arg1[(arg4 >> 16) + i3] & 0xff;
						if (arg3 != 0) {
							arg3 = arg2[arg3];
							int j = arg3 >> 16 & 0xff;
							int k = arg3 >> 8 & 0xff;
							int l = arg3 & 0xff;
							if (j == k && k == l) {
								arg0[j4 + arg6] = ((j * i1 >> 8) << 16)
										+ ((k * j1 >> 8) << 8) + (l * k1 >> 8);
							} else if (j == 255 && k == l) {
								arg0[j4 + arg6] = ((j * l1 >> 8) << 16)
										+ ((k * i2 >> 8) << 8) + (l * j2 >> 8);
							} else {
								arg0[j4 + arg6] = arg3;
							}
						}
						arg4 += arg9;
					}

				}
				arg5 += arg10;
				arg4 = k2;
				arg6 += menuDefaultWidth;
				arg14 += arg15;
			}

			return;
		} catch (Exception _ex) {
			System.out.println("error in transparent sprite plot routine");
		}
	}

	public static int ye(byte arg0[]) {
		sk[uk] = arg0;
		return uk++;
	}

	public void sg(String arg0, int arg1, int arg2, int arg3, int arg4) {
		drawString(arg0, arg1 - textWidth(arg0, arg3), arg2, arg3, arg4);
	}

	public void drawText(String arg0, int arg1, int arg2, int arg3, int arg4) {
		drawString(arg0, arg1 - textWidth(arg0, arg3) / 2, arg2, arg3, arg4);
	}

	public void ug(String arg0, int arg1, int arg2, int arg3, int arg4, int arg5) {
		int j = 0;
		byte abyte0[] = sk[arg3];
		int k = 0;
		int l = 0;
		for (int i1 = 0; i1 < arg0.length(); i1++) {
			if (arg0.charAt(i1) == '@' && i1 + 4 < arg0.length()
					&& arg0.charAt(i1 + 4) == '@') {
				i1 += 4;
			} else if (arg0.charAt(i1) == '~' && i1 + 4 < arg0.length()
					&& arg0.charAt(i1 + 4) == '~') {
				i1 += 4;
			} else {
				j += abyte0[charIndexes[arg0.charAt(i1)] + 7];
			}
			if (arg0.charAt(i1) == ' ') {
				l = i1;
			}
			if (j > arg5) {
				if (l <= k) {
					l = i1;
				}
				drawText(arg0.substring(k, l), arg1, arg2, arg3, arg4);
				j = 0;
				k = i1 = l + 1;
				arg2 += messageFontHeight(arg3);
			}
		}

		if (j > 0) {
			drawText(arg0.substring(k), arg1, arg2, arg3, arg4);
		}
	}

	public void drawString(String string, int arg1, int arg2, int arg3, int colour) {
		byte abyte0[] = sk[arg3];
		for (int offset = 0; offset < string.length(); offset++) {
			if (string.charAt(offset) == '@' && offset + 4 < string.length()
					&& string.charAt(offset + 4) == '@') {
				if (string.substring(offset + 1, offset + 4).equalsIgnoreCase(
						"red")) {
					colour = 0xff0000;
				} else if (string.substring(offset + 1, offset + 4)
						.equalsIgnoreCase("lre")) {
					colour = 0xff9040;
				} else if (string.substring(offset + 1, offset + 4)
						.equalsIgnoreCase("yel")) {
					colour = 0xffff00;
				} else if (string.substring(offset + 1, offset + 4)
						.equalsIgnoreCase("gre")) {
					colour = 65280;
				} else if (string.substring(offset + 1, offset + 4)
						.equalsIgnoreCase("blu")) {
					colour = 255;
				} else if (string.substring(offset + 1, offset + 4)
						.equalsIgnoreCase("cya")) {
					colour = 65535;
				} else if (string.substring(offset + 1, offset + 4)
						.equalsIgnoreCase("mag")) {
					colour = 0xff00ff;
				} else if (string.substring(offset + 1, offset + 4)
						.equalsIgnoreCase("whi")) {
					colour = 0xffffff;
				} else if (string.substring(offset + 1, offset + 4)
						.equalsIgnoreCase("bla")) {
					colour = 0;
				} else if (string.substring(offset + 1, offset + 4)
						.equalsIgnoreCase("dre")) {
					colour = 0xc00000;
				} else if (string.substring(offset + 1, offset + 4)
						.equalsIgnoreCase("ora")) {
					colour = 0xff9040;
				} else if (string.substring(offset + 1, offset + 4)
						.equalsIgnoreCase("ran")) {
					colour = (int) (Math.random() * 16777215D);
				} else if (string.substring(offset + 1, offset + 4)
						.equalsIgnoreCase("or1")) {
					colour = 0xffb000;
				} else if (string.substring(offset + 1, offset + 4)
						.equalsIgnoreCase("or2")) {
					colour = 0xff7000;
				} else if (string.substring(offset + 1, offset + 4)
						.equalsIgnoreCase("or3")) {
					colour = 0xff3000;
				} else if (string.substring(offset + 1, offset + 4)
						.equalsIgnoreCase("gr1")) {
					colour = 0xc0ff00;
				} else if (string.substring(offset + 1, offset + 4)
						.equalsIgnoreCase("gr2")) {
					colour = 0x80ff00;
				} else if (string.substring(offset + 1, offset + 4)
						.equalsIgnoreCase("gr3")) {
					colour = 0x40ff00;
				}
				offset += 4;
			} else if (string.charAt(offset) == '~'
					&& offset + 4 < string.length()
					&& string.charAt(offset + 4) == '~') {
				char c = string.charAt(offset + 1);
				char c1 = string.charAt(offset + 2);
				char c2 = string.charAt(offset + 3);
				if (c >= '0' && c <= '9' && c1 >= '0' && c1 <= '9' && c2 >= '0'
						&& c2 <= '9') {
					arg1 = Integer.parseInt(string.substring(offset + 1,
							offset + 4));
				}
				offset += 4;
			} else {
				int k = charIndexes[string.charAt(offset)];
				if (vk && colour != 0) {
					lg(k, arg1 + 1, arg2, 0, abyte0);
				}
				if (vk && colour != 0) {
					lg(k, arg1, arg2 + 1, 0, abyte0);
				}
				lg(k, arg1, arg2, colour, abyte0);
				arg1 += abyte0[k + 7];
			}
		}

	}

	private void lg(int arg0, int arg1, int arg2, int arg3, byte arg4[]) {
		int j = arg1 + arg4[arg0 + 5];
		int k = arg2 - arg4[arg0 + 6];
		int l = arg4[arg0 + 3];
		int i1 = arg4[arg0 + 4];
		int j1 = arg4[arg0] * 16384 + arg4[arg0 + 1] * 128 + arg4[arg0 + 2];
		int k1 = j + k * menuDefaultWidth;
		int l1 = menuDefaultWidth - l;
		int i2 = 0;
		if (k < imageY) {
			int j2 = imageY - k;
			i1 -= j2;
			k = imageY;
			j1 += j2 * l;
			k1 += j2 * menuDefaultWidth;
		}
		if (k + i1 >= imageHeight) {
			i1 -= ((k + i1) - imageHeight) + 1;
		}
		if (j < imageX) {
			int k2 = imageX - j;
			l -= k2;
			j = imageX;
			j1 += k2;
			k1 += k2;
			i2 += k2;
			l1 += k2;
		}
		if (j + l >= imageWidth) {
			int l2 = ((j + l) - imageWidth) + 1;
			l -= l2;
			i2 += l2;
			l1 += l2;
		}
		if (l > 0 && i1 > 0) {
			plotLetter(imagePixelArray, arg4, arg3, j1, k1, l, i1, l1, i2);
		}
	}

	private void plotLetter(int arg0[], byte arg1[], int arg2, int arg3,
			int arg4, int arg5, int arg6, int arg7, int arg8) {
		int j = -(arg5 >> 2);
		arg5 = -(arg5 & 3);
		for (int k = -arg6; k < 0; k++) {
			for (int l = j; l < 0; l++) {
				if (arg1[arg3++] != 0) {
					arg0[arg4++] = arg2;
				} else {
					arg4++;
				}
				if (arg1[arg3++] != 0) {
					arg0[arg4++] = arg2;
				} else {
					arg4++;
				}
				if (arg1[arg3++] != 0) {
					arg0[arg4++] = arg2;
				} else {
					arg4++;
				}
				if (arg1[arg3++] != 0) {
					arg0[arg4++] = arg2;
				} else {
					arg4++;
				}
			}

			for (int i1 = arg5; i1 < 0; i1++) {
				if (arg1[arg3++] != 0) {
					arg0[arg4++] = arg2;
				} else {
					arg4++;
				}
			}

			arg4 += arg7;
			arg3 += arg8;
		}

	}

	public int messageFontHeight(int arg0) {
		if (arg0 == 0) {
			return sk[arg0][8] - 2;
		} else {
			return sk[arg0][8] - 1;
		}
	}

	public int textWidth(String s, int i) {
		int j = 0;
		byte abyte0[] = sk[i];
		for (int k = 0; k < s.length(); k++) {
			if (s.charAt(k) == '@' && k + 4 < s.length()
					&& s.charAt(k + 4) == '@') {
				k += 4;
			} else if (s.charAt(k) == '~' && k + 4 < s.length()
					&& s.charAt(k + 4) == '~') {
				k += 4;
			} else {
				j += abyte0[charIndexes[s.charAt(k)] + 7];
			}
		}
		return j;
	}

	public boolean imageUpdate(Image image, int arg1, int arg2, int j, int k,
			int l) {
		return true;
	}

	public int menuDefaultWidth;
	public int menuDefaultHeight;
	public int uj;
	public int imageWidthUnused;
	public int imageHeightUnused;
	ColorModel colourModel;
	public int imagePixelArray[];
	ImageConsumer imageConsumer;
	private Component ak;
	public Image image;
	private int ck[][];
	private byte dk[][];
	private int ek[][];
	public int fk[];
	public int gk[];
	public int hk[];
	public int ik[];
	public int jk[];
	public int kk[];
	public boolean lk[];
	private boolean mk;
	private int imageY;
	private int imageHeight;
	private int imageX;
	private int imageWidth;
	public boolean rk;
	static byte sk[][] = new byte[50][];
	static int charIndexes[];
	static int uk;
	public boolean vk;
	int wk[];
	int xk[];
	int yk[];
	int zk[];
	int al[];
	int bl[];
	int cl[];
	public static final int dl = 0;
	public static final int el = 0xffffff;
	public static final int fl = 0xff0000;
	public static final int gl = 0xc00000;
	public static final int hl = 65280;
	public static final int il = 255;
	public static final int jl = 0xffff00;
	public static final int kl = 65535;
	public static final int ll = 0xff00ff;
	public static final int ml = 0xc0c0c0;
	public static final int nl = 0x808080;
	public static final int ol = 0x404040;
	public static final int pl = 0;
	public static final int ql = 1;
	public static final int rl = 2;
	public static final int sl = 3;
	public static final int tl = 4;
	public static final int ul = 5;
	public static final int vl = 6;
	public static final int wl = 7;

	static {
		String s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!\"\243$%^&*()-_=+[{]};:'@#~,<.>/?\\| ";
		charIndexes = new int[256];
		for (int j = 0; j < 256; j++) {
			int k = s.indexOf(j);
			if (k == -1) {
				k = 74;
			}
			charIndexes[j] = k * 9;
		}

	}
}
